package BBDD;

import java.sql.*;
import java.util.ArrayList;
import java.util.Vector;
import java.util.logging.Level;
import java.util.logging.Logger;

import DAO.AlumnoDAO;
import DAO.CicloDAO;

public class ManageCiclo {

	private Connection conn;
	private Statement pstmt;
	private ResultSet rs;
	private String query;
	private ManageDB abreConn;
	private Vector<CicloDAO> ciclo;

	public ManageCiclo() {
		abreConn = new ManageDB();
		conn = abreConn.getConnection();	
		abreConn.OpenDB();
	}

	public void loadDataCiclo(String query) {
		this.query = query;
		conn = abreConn.getConnection();
		
		try {
			pstmt = conn.createStatement();
			rs = pstmt.executeQuery(query);		
			
			
			while (rs.next()) {
				int idCiclo= rs.getInt(1);
				int idFamilia = rs.getInt(2);
				String nombreCiclo = rs.getString(3);
				setCiclo(new CicloDAO(idCiclo, idFamilia, nombreCiclo));

			}

		} catch (SQLException ex) {
			Logger.getLogger(ManageCiclo.class.getName()).log(Level.SEVERE,
					null, ex);
		} finally {
			try {
				rs.close();
				pstmt.close();
			} catch (SQLException e) {
				e.printStackTrace();
			}

		}
	}

	public void updateCiclo(String query) {
		this.query = query;

		conn = abreConn.getConnection();

		try {

			pstmt = conn.prepareStatement(query);
			pstmt.execute(query);
		} catch (SQLException ex) {
			Logger.getLogger(ManageCiclo.class.getName()).log(Level.SEVERE,
					null, ex);
		} finally {

			try {

				pstmt.close();
			} catch (SQLException e) {
				e.printStackTrace();
			}
		}
	}

	public void deleteCiclo(String query) {
		this.query = query;

		conn = abreConn.getConnection();

		try {

			pstmt = conn.prepareStatement(query);
			pstmt.execute(query);
		} catch (SQLException ex) {
			Logger.getLogger(ManageCiclo.class.getName()).log(Level.SEVERE,
					null, ex);
		} finally {

			try {

				pstmt.close();
			} catch (SQLException e) {
				e.printStackTrace();
			}
		}
	}

	public String getOldQuery() {
		return query;
	}

	public Vector<CicloDAO> getCiclo() {
		return ciclo;
	}

	public void setCiclo(CicloDAO ciclo) {
		this.ciclo.add(ciclo);
	}

}
